package com.example.user.biz.mapper;

import com.example.user.biz.domain.vo.AddressVO;
import com.example.user.biz.domain.po.Address;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AddressMapper {
    /**
     * 查询当前用户的收货地址列表
     * @param address
     * @return 收货地址列表
     */
     List<AddressVO> list(Address address);

    /**
     * 删除收货地址
     * @param id 收货地址id
     */
    @Select("DELETE FROM address WHERE id = #{id}")
    void deleteAddress(Integer id);

    @Insert("INSERT INTO address (user_id,receiver, contact, full_location, province_code, city_code, county_code, address, is_default) VALUES (#{userId},#{receiver}, #{contact}, #{fullLocation}, #{provinceCode}, #{cityCode}, #{countyCode}, #{address}, #{isDefault})")
    void insert(Address address);


    /**
     * 设置收货地址全为非默认地址
     * @param address
     */
    @Update("UPDATE address SET is_default = #{isDefault} WHERE user_id = #{userId}")
    void updateIsDefaultByUserId(Address address);

    void update(Address address);
}
